//
//  SettingViewController.m
//  YJlandlord
//
//  Created by 文彬 on 2018/6/26.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "SettingViewController.h"
#import "MessItemTableViewCell.h"
#import "SevenSwitch.h"
#import "FeedBackViewController.h"

@interface SettingViewController ()<UITableViewDelegate,
    UITableViewDataSource>

@property (strong, nonatomic) UITableView *listTableView;
@property (strong, nonatomic) NSArray *titles;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"设置";
    
    self.titles = @[@[@"账号和安全"],
                    @[@"推荐给好友",@"意见反馈",@"给意居好评",@"APP版本",@"放心消费声明"],
                    @[@"推送设置",@"清除缓存"]];
    
    [self initPageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark 页面相关
- (void)initPageControl{
    
    [self.view addSubview:self.listTableView];
    [self.listTableView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    
    [StaticTools addTableViewFootButton:self.listTableView
                                  title:@"退出登录"
                              titleFont:[UIFont systemFontOfSize:18]
                        backgroundColor:[UIColor whiteColor]
                             titleColor:kMainOriginColor
                           buttonHeight:50
                              topMargin:15
                             leftMargin:0
                                  click:^(id param) {
                                      
                                      
                                      
                                  }];
}
#pragma mark UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section==1) {
        return 5;
    }
    else if(section==2){
        return 2;
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==2&&indexPath.row==0) {
        
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"iden"];
        UILabel *titleLabel  = [[UILabel alloc]init];
        titleLabel.font = [UIFont systemFontOfSize:15];
        titleLabel.text = @"推送设置";
        titleLabel.textColor = kTitleColor;
        [cell.contentView addSubview:titleLabel];
        [titleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@15);
            make.width.equalTo(@100);
            make.height.equalTo(@30);
            make.centerY.equalTo(cell.contentView.centerY);
        }];
        
        SevenSwitch *pushSwitch = [[SevenSwitch alloc]init];
        [cell.contentView addSubview: pushSwitch];
        pushSwitch.onColor = kMainOriginColor;
        pushSwitch.inactiveColor = [UIColor lightGrayColor];
        pushSwitch.on = YES;
//        [pushSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        [pushSwitch makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@40);
            make.height.equalTo(@25);
            make.centerY.equalTo(cell.contentView.centerY);
            make.right.equalTo(@-10);
        }];
        
        return cell;
    }
    MessItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessItemTableViewCell"];
    cell.detailLabel.text = @"";
    cell.titleLabel.text = self.titles[indexPath.section][indexPath.row];
    [cell showImage:NO];
    [cell showArrow:YES];
    
    if ((indexPath.section==1&&indexPath.row==3)||
        (indexPath.section==2&&indexPath.row==1)) {
        [cell showArrow:NO];
        
        if (indexPath.section==1) {
            cell.detailLabel.text = @"当前版本 6.4.0";
        }
        else{
            cell.detailLabel.text = @"103MB";
        }
    }
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section==1) {
        if (indexPath.row==1) { //意见反馈
            FeedBackViewController *feedbackController = [[FeedBackViewController alloc]init];
            [self.navigationController pushViewController:feedbackController animated:YES];
        }
    }
}

#pragma mark getter
- (UITableView*)listTableView{
    if (_listTableView==nil) {
        _listTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.sectionFooterHeight = 0;
        _listTableView.separatorColor = kLineColor;
        _listTableView.backgroundColor = [UIColor clearColor];
        [_listTableView registerNib:[UINib nibWithNibName:@"MessItemTableViewCell" bundle:nil] forCellReuseIdentifier:@"MessItemTableViewCell"];
    }
    
    return _listTableView;
}


@end
